<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

	protected $fillable = array('username', 'password', 'email', 'first_name', 'last_name', 'role_id', 'department_id');

	use UserTrait, RemindableTrait;

	public function role() {
        return $this->belongsTo('Role');
	}
	
	public function department() {
        return $this->belongsTo('Department');
	}
	
	public function isAdmin() {
		return $this->role->role_name == 'Administrator';
	}
	
	// /**
     // * Get the roles a user has
     // */
    // public function departments()
    // {
        // return $this->belongsToMany('Department', 'users_departments');
    // }
	
	// /**
     // * Find out if User is an employee, based on if has any roles
     // *
     // * @return boolean
     // */
    // public function isDepartment()
    // {
        // $departments = $this->departments->toArray();
        // return !empty($departments);
    // }
 
    // /**
     // * Find out if user has a specific role
     // *
     // * $return boolean
     // */
    // public function hasDepartment($check)
    // {
        // return in_array($check, array_fetch($this->departments->toArray(), 'name'));
    // }
 
    // /**
     // * Get key in array with corresponding value
     // *
     // * @return int
     // */
    // private function getIdInArray($array, $term)
    // {
        // foreach ($array as $value) {
            // if ($value['name'] == $term) {
                // return $value['id'];
            // }
        // }
 
        // throw new UnexpectedValueException;
    // }
 
    // /**
     // * Add roles to user to make them a concierge
     // */
    // public function makeEmployee($title)
    // {
        // $assigned_departments = array();

		// $departmentsAll = Department::all()->toArray();
		
        // $this->departments()->attach($assigned_departments);
    // }
	
	/**
	 * The database table used by the model.
	 *
	 * @var string
	 */
	protected $table = 'users';

	/**
	 * The attributes excluded from the model's JSON form.
	 *
	 * @var array
	 */
	protected $hidden = array('password', 'remember_token');

}
